package org.rc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.rc.dto.SxzjPageDto;
import org.rc.entity.Sxzj;
import org.rc.mapper.SxzjMapper;
import org.rc.service.SxzjService;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class SxzjServiceImpl extends ServiceImpl<SxzjMapper, Sxzj> implements SxzjService {
    @Override
    public void addSxzj(Sxzj sxzj) {
        this.save(sxzj);
    }

    @Override
    public Page<Sxzj> getSxzjPage(SxzjPageDto sxzjPageDto) {
        Page<Sxzj> page = new Page<>(sxzjPageDto.getPageNo(),sxzjPageDto.getPageSize());
        QueryWrapper<Sxzj> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(sxzjPageDto.getName()),"name",sxzjPageDto.getName());
        return this.baseMapper.selectPage(page,queryWrapper);
    }

    @Override
    public void updateSxzj(Sxzj sxzj) {
        this.updateById(sxzj);
    }

    @Override
    public void deleteSxzj(Long id) {
        this.removeById(id);
    }

    @Override
    public void batchDeleteSxzj(List<Long> ids) {
        this.removeByIds(ids);
    }

    @Override
    public List<Sxzj> getAllSxzj() {
        return list();
    }

    @Override
    public Sxzj getSxzjById(Long id) {
        return this.getById(id);
    }

    @Override
    public List<Sxzj> getSxzjByIds(List<Long> ids) {
        return this.listByIds(ids);
    }
}
